# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=kopia
pkgver=0.15.0
pkgrel=2
pkgdesc="Fast and secure backup tool"
url="https://kopia.io/"
license="Apache-2.0"
arch="all !armhf !armv7 !x86" # tests fail with out of memory error
makedepends="go"
subpackages="$pkgname-bash-completion $pkgname-zsh-completion"
checkdepends="openssh-keygen"
source="
	https://github.com/kopia/kopia/archive/v$pkgver/kopia-$pkgver.tar.gz
	skip-docker-tests.patch
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
export CGO_ENABLED=1

build() {
	local _goldflags="
	-X github.com/kopia/kopia/repo.BuildVersion=$pkgver
	-X github.com/kopia/kopia/repo.BuildInfo=AlpineLinux
	-X github.com/kopia/kopia/repo.BuildGitHubRepo=kopia/kopia
	"
	go build -ldflags "$_goldflags"

	./kopia --completion-script-bash > $pkgname.bash
	./kopia --completion-script-zsh > $pkgname.zsh
}

check() {
	# XXX: end to end restore_test fails to get same buffer from backup
	# shellcheck disable=2046
	go test -timeout=30m \
		$(go list -tags testing ./... | grep -Ev 'end_to_end_test')
}

package() {
	install -Dm755 kopia -t "$pkgdir"/usr/bin/

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
c12e75457d6a77d6968f1e577efdb5703ce6fa99991e3088a73e9b5dfa51fdfa96d8264e62a9fad1b2ee8ce07d98ca3bfd986acbc4dac277b2a84ec3187cfd97  kopia-0.15.0.tar.gz
6c1c8ca52d83c940c561f11adc18298147882b709810edd8c6560c8988ff1bd30dae2adba4c18055d283e7c2c655a6c6f10c3951829826d6fe5eea20c8cb821d  skip-docker-tests.patch
"
